package com.burgeon.backend.EnterpriseWeChat.service.Impl;

import com.burgeon.backend.EnterpriseWeChat.entity.Vip;
import com.burgeon.backend.EnterpriseWeChat.mappers.EWCustomerAssistantMapper;
import com.burgeon.backend.EnterpriseWeChat.rest.VipInfo.findVipInfo;
import com.burgeon.backend.EnterpriseWeChat.rest.VipInfo.findVipInfoById;
import com.burgeon.backend.EnterpriseWeChat.rest.VipInfo.updateVipInfoById;
import com.burgeon.backend.EnterpriseWeChat.service.EWCustomerAssistantService;
import com.burgeon.backend.SHOP.entity.Goods;
import com.burgeon.backend.entity.Info;
import com.burgeon.backend.mappers.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EWCustomerAssistantServiceImpl implements EWCustomerAssistantService {

    @Autowired
    private EWCustomerAssistantMapper ewCustomerAssistantMapper;
    @Autowired
    private AccountMapper accountMapper;


    @Override
    public List<Goods> findGoodsData(String content, String token) {
        List<Goods> data = ewCustomerAssistantMapper.findGoodsData(content,token);
        return data;
    }

    @Override
    public Goods findGoodsById(String id, String token) {
        Goods data = ewCustomerAssistantMapper.findGoodsById(id,token);
        return data;
    }

    @Override
    public void updateGoodsData(String token, String id, String price, String isPutAway) {
        ewCustomerAssistantMapper.updateGoodsData(token,id,price,isPutAway);
    }

    @Override
    public ArrayList<Vip> findVipData(String nameOrCardNo, int range, String token) throws Exception {
        Info info = GetInfoByToken(token);
        findVipInfo findVipInfo = new findVipInfo(info.getUrl(), info.getAccount(), info.getPassword());
        ArrayList<Vip> data = findVipInfo.getData(nameOrCardNo, range);
        return data;
    }

    @Override
    public Vip findVipDataById(String token, String id) throws Exception {
        Info info = GetInfoByToken(token);
        findVipInfoById findVipInfoById = new findVipInfoById(info.getUrl(), info.getAccount(), info.getPassword());
        Vip data = findVipInfoById.getData(id);
        return data;
    }

    @Override
    public void updateVipData(String token, String id, String img, String name, String birthday, String phone,String cardNo) throws Exception {
        Info info = GetInfoByToken(token);
        updateVipInfoById updateVipInfoById = new updateVipInfoById(info.getUrl(), info.getAccount(), info.getPassword());
        updateVipInfoById.getData(id,img,name,birthday,phone);
        ewCustomerAssistantMapper.updateVipById(cardNo,name,birthday,token);

    }

    private Info GetInfoByToken(String token) {
        return accountMapper.GetTokenData(token);
    }
}
